package session;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import entities.Company;
import entities.Intern;
import entities.ProgLanguage;

/**
 * Login sayfasindan yonlendirme yaparken sessionda tutlmasi istenilen
 * nesnelerin aktarildigi sinif..
 * 
 * @author gurkan
 */
@Name("userData")
@Scope(ScopeType.SESSION)
public class UserData {

	
	private Company company;
	private Intern intern;
	private String language;
	private List<ProgLanguage> languageList;

    @In
    private EntityManager entityManager;
	
	/**
	 * Stajyer ogrencinin ozgecmis bilgilerini veritabanina kaydeder..
	 */
	public void saveUserData() {
		intern.setLanguageList(languageList);
		entityManager.merge(intern);
	}
	
	/**
	 * Stajyerin ozgemisine programlama dili ekler.. 
	 */
	public void addLanguage() {
		if(languageList == null)
			languageList = new ArrayList<ProgLanguage>();
	    
		// yeni bir dil yarat..
		ProgLanguage pl = new ProgLanguage(language,intern);
	    languageList.add(pl);
	    System.out.println("**********************************************************");
	}
	
	/**
	 * Stajyer sayfasi icin programlama dilleri yaratir..
	 * 
	 * @return
	 */
	public List<SelectItem> getSelectItems() {
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		selectItems.add(new SelectItem("Java", "Java"));
		selectItems.add(new SelectItem("Python", "Python"));
		selectItems.add(new SelectItem("Lisp", "Lisp"));
		selectItems.add(new SelectItem("Cobol", "Cobol"));
		selectItems.add(new SelectItem("Javascript", "Javascript"));
		selectItems.add(new SelectItem("C", "C"));
		selectItems.add(new SelectItem("PL/I", "PL/I"));
		selectItems.add(new SelectItem("Perl", "Perl"));
		return selectItems;
	}
	
	public String yankeesGoHome() {
		return "home";
	}
	
	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public Intern getIntern() {
		return intern;
	}

	public void setIntern(Intern intern) {
		this.intern = intern;
	}


	public String getLanguage() {
		return language;
	}


	public void setLanguage(String language) {
		this.language = language;
	}

	public List<ProgLanguage> getLanguageList() {
		return languageList;
	}

	public void setLanguageList(List<ProgLanguage> languageList) {
		this.languageList = languageList;
	}


}
